package com.bawei.module_live.version1

import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.media3.ui.PlayerView
import com.bawei.module_live.R
import com.bawei.module_live.player.ExoPlayerManager

class TestVideoActivity : AppCompatActivity() {
    
    companion object {
        private const val TAG = "TestVideoActivity"
    }
    
    private lateinit var playerView: PlayerView
    private lateinit var exoPlayerManager: ExoPlayerManager
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_test_video)
        
        playerView = findViewById(R.id.player_view)
        exoPlayerManager = ExoPlayerManager(this)
        
        setupPlayer()
        testVideoPlayback()
    }
    
    private fun setupPlayer() {
        try {
            exoPlayerManager.setPlayerView(playerView)
            Log.d(TAG, "播放器设置完成")
        } catch (e: Exception) {
            Log.e(TAG, "设置播放器失败: ${e.message}")
        }
    }
    
    private fun testVideoPlayback() {
        try {
            // 创建测试视频数据
            val testVideo = VideoEntityItem(
                avatar_url = "",
                channelid = "test",
                commentnum = 100,
                ctime = "",
                description = "测试视频",
                group_id = "test",
                id = 1,
                image_url = "",
                item_id = "test",
                labelIds = "",
                name = "测试用户",
                playnum = 1000,
                preview_url = "",
                publish_time = "",
                title = "测试视频标题",
                userid = "test",
                verifycode = "",
                videomainimag = "",
                videopath = "" // 空路径，会使用测试视频
            )
            
            // 播放测试视频
            exoPlayerManager.playVideo(testVideo, 0)
            Toast.makeText(this, "开始播放测试视频", Toast.LENGTH_SHORT).show()
            
        } catch (e: Exception) {
            Log.e(TAG, "测试视频播放失败: ${e.message}")
            e.printStackTrace()
        }
    }
    
    override fun onDestroy() {
        super.onDestroy()
        exoPlayerManager.release()
    }
} 